package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.domain.MediaFile;
import cn.itsource.ymcc.service.IMediaFileService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.netty.util.CharsetUtil;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

@Component
@RocketMQMessageListener(topic = "course",selectorExpression = "media",consumerGroup = "service-media-producer",messageModel = MessageModel.CLUSTERING)
public class MessageConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private IMediaFileService iMediaFileService;
    @Override
    public void onMessage(MessageExt messageExt) {
        String msg = new String(messageExt.getBody(), StandardCharsets.UTF_8);
        MediaFile mediaFile = JSON.parseObject(msg,MediaFile.class);
        iMediaFileService.handleFile2m3u8(mediaFile);
    }
}
